package com.ruanjian.eduservice.service.impl;


import com.ruanjian.commonUtils.R;
import com.ruanjian.eduservice.entity.EduCourse;
import com.ruanjian.eduservice.entity.EduCourseDescription;
import com.ruanjian.eduservice.mapper.EduCourseMapper;
import com.ruanjian.eduservice.service.EduCourseDescriptionService;
import com.ruanjian.eduservice.service.EduCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruanjian.eduservice.vo.CourseInfoForm;
import com.ruanjian.serviceBase.MyException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * <p>
 * 课程 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-12-15
 */
@Service
public class EduCourseServiceImpl extends ServiceImpl<EduCourseMapper, EduCourse> implements EduCourseService {

    @Autowired
    private EduCourseDescriptionService eduCourseDescriptionService;
    //添加课程信息
    @Override
    public void saveCourseInfo(CourseInfoForm courseInfoForm) {
        EduCourse eduCourse=new EduCourse();
        BeanUtils.copyProperties(courseInfoForm,eduCourse);
        int insert = baseMapper.insert(eduCourse);
        if(insert==0)
        {
            throw new MyException(20001,"添加课程失败");
        }
        //添加课程简介
        String id = eduCourse.getId();
        EduCourseDescription eduCourseDescription=new EduCourseDescription();
        eduCourseDescription.setId(id);
        eduCourseDescription.setDescription(courseInfoForm.getDescription());
        eduCourseDescriptionService.save(eduCourseDescription);
    }




}
